//
// Created by 吴锐 on 2022/2/28.
//

#include "iostream"
#include "vector"

using namespace std;

class Person{
public:
    string name;
    int age;

    Person(string name, int age){
        this->name = name;
        this->age = age;
    }
};

void test01(){
    vector<Person> v;
    Person p1("aaa", 10);
    Person p2("bbb", 20);
    Person p3("ccc", 30);
    Person p4("ddd", 40);
    Person p5("eee", 50);

    v.push_back(p1);
    v.push_back(p2);
    v.push_back(p3);
    v.push_back(p4);
    v.push_back(p5);

    //遍历容器中的数据
    for(vector<Person>::iterator it = v.begin() ; it != v.end() ; it++){
//        cout << "姓名: " << (*it).name << " 年龄: " << (*it).age << endl;
        cout << "姓名: " << it->name << " 年龄: " << it->age << endl;
    }
}

void test02(){
    vector<Person*> v;
    Person p1("aaa", 10);
    Person p2("bbb", 20);
    Person p3("ccc", 30);
    Person p4("ddd", 40);
    Person p5("eee", 50);

    v.push_back(&p1);
    v.push_back(&p2);
    v.push_back(&p3);
    v.push_back(&p4);
    v.push_back(&p5);

    for(vector<Person*>::iterator it = v.begin(); it != v.end(); it++){
        cout << "name: " << (*it)->name << " age: " << (*it)->age << endl;
    }
}

int main(){
//    test01();
    test02();
    return 0;
}